package org.opengraph.entities;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.*;

public class User  extends Entity{
	
	private String id;
	private String name;
	private String first_name;
	private String last_name;
	private String link;
	
	public static User getUser(String userName,String accessCode) throws Exception{
		String userJson = getJson(userName, accessCode);
		Gson gson = new Gson();
		return gson.fromJson(userJson,User.class);
	}
	
	public String toString(){
		return getFirst_name() + " " + getLast_name();
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getFirst_name() {
		return first_name;
	}
	public void setFirst_name(String firstName) {
		first_name = firstName;
	}
	public String getLast_name() {
		return last_name;
	}
	public void setLast_name(String lastName) {
		last_name = lastName;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	
	public List<Feed> getFeeds(String accessCode) throws Exception{
		//Type listType = new TypeToken<ArrayList<Feed>>() {}.getType();
		String json = getJson(this.id+"/home",accessCode);
		Type datatype = new TypeToken<DataHelper<Feed>>() {}.getType();
		DataHelper<Feed> data =  gson.fromJson(json,datatype);
		return data.getData();
		
	}
	public List<User> getFriends(String accessCode) throws Exception{
		String json = getJson(this.id+"/friends",accessCode);
		Type datatype = new TypeToken<DataHelper<User>>() {}.getType();
		DataHelper<User> data =  gson.fromJson(json,datatype);
		return data.getData();
	}
}
